﻿using System;
using System.Linq.Expressions;
using Glue.Internals;
using GlueTests.Builders;
using Xunit;

namespace GlueTests.PropertyFactoryTests
{
    public class When_creating_properties_from_methods
    {
        private readonly ObjectMemberFactory factory;

        public When_creating_properties_from_methods()
        {
            factory = new ObjectMemberFactoryBuilder().Build();
        }


        [Fact]
        public void Should_return_Property_when_converting_method_with_return_value_and_no_parameter()
        {
            factory.CreateObjectMember(PersonWithAllKindsOfProperties.GetLambda(x => x.AmethodWithReturnValueAndNoParameters()));
        }

        [Fact]
        public void Should_throw_exception_when_converting_method_with_no_return_value()
        {
            Expression<Action<PersonWithAllKindsOfProperties>> expression = x => x.AmethodWithNoReturnValue();
            Assert.Throws(typeof(ArgumentException), 
               ()=> factory.CreateObjectMember(expression)
            );
        }

        [Fact]
        public void Should_throw_exception_when_converting_method_with_parameters()
        {
            Assert.Throws(typeof(ArgumentException),
               () => factory.CreateObjectMember(PersonWithAllKindsOfProperties.GetLambda(x=>x.AMethodWithParameters(1)))
            );
        }
    }
}
